package com.mzj.saas.mservice.contract.repository;

import com.mzj.saas.mservice.contract.entity.Contract;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

public interface ContractRepository extends PagingAndSortingRepository<Contract, String>, JpaSpecificationExecutor<Contract> {
    Contract findByHouseIdAndStatus(String houseId, Integer status);

    List<Contract> findByContractNubmerIn(List<String> contractNubmers);

    Contract findByContractId(String contractId);

    Contract findByContractNubmer(String contractNubmers);

    List<Contract> findByStatusAndContractNubmerIn(Integer status, List<String> contractNubmers);

    @Query(value = "select * from saas_house_contract where house_id = ?1 and match_user_id = ?2 and status != 0", nativeQuery = true)
    Contract findByHouseIdAndMatchUserId(String houseId, String matchUserId);

    List<Contract> findByHouseId(String houseId);

    @Modifying
    @Query(value = "UPDATE saas_house_contract SET status = 10 WHERE house_id = ?1", nativeQuery = true)
    Integer updateStatusByHouseId(String houseId);

}
